﻿using System;
using System.ComponentModel;
using System.Windows.Input;
using DataStore.Domain;
using DataStore.Repositories;
using Microsoft.Practices.Composite.Events;

namespace Infrastructure.ViewModels
{
    /// <summary>
    /// Keyword viewmodel
    /// </summary>
    public class KeywordViewModel : DataModelSingle<Keyword>, IDataErrorInfo
    {

        /// <summary>
        /// Initializes a new instance of the <see cref="KeywordViewModel"/> class.
        /// </summary>
        /// <param name="keyword">The keyword.</param>
        public KeywordViewModel(IEventAggregator eventAggregator, Keyword keyword) : base(eventAggregator, keyword)
        {
            
        }

        /// <summary>
        /// Gets the keyword entity.
        /// </summary>
        /// <value>The keyword.</value>
        public Keyword Keyword
        {
            get
            {
                return Item;
            }
        }

        /// <summary>
        /// Gets or sets the id.
        /// </summary>
        /// <value>The id.</value>
        public virtual Guid Id
        {
            get
            {
                return Item.Id;
            }
            set
            {
                Item.Id = value;
                OnPropertyChanged("Id");
            }
        }
        /// <summary>
        /// Gets or sets the text.
        /// </summary>
        /// <value>The text.</value>
        public virtual string Text
        {
            get
            {
                return Item.Text;
            }
            set
            {
                Item.Text = value;
                OnPropertyChanged("Text");
            }
        }

        bool _selected;
        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="KeywordViewModel"/> is selected.
        /// </summary>
        /// <value><c>true</c> if selected; otherwise, <c>false</c>.</value>
        public bool Selected
        {
            get
            {
                return _selected;
            }
            set
            {
                _selected = value;
                OnPropertyChanged("Selected");
            }
        }

        #region IDataErrorInfo Members

        /// <summary>
        /// Gets an error message indicating what is wrong with this object.
        /// </summary>
        /// <value></value>
        /// <returns>An error message indicating what is wrong with this object. The default is an empty string ("").</returns>
        public string Error
        {
            get { return (Item as IDataErrorInfo).Error; }
        }

        /// <summary>
        /// Gets the <see cref="System.String"/> with the specified column name.
        /// </summary>
        /// <value></value>
        public string this[string columnName]
        {
            get
            {
                string error = string.Empty;
                error = (Item as IDataErrorInfo)[columnName];

                CommandManager.InvalidateRequerySuggested();
                return error;
            }
        }

        #endregion
    }
}